import java.sql.*;

public class JDBCTxTest {

    static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
    static final String CONN_URL = "jdbc:mysql://127.0.0.1:3306/sakila?useSSL=false";
    static final String USER = "root";
    static final String PASS = "123456";

    public static void main(String[] args) throws SQLException {

        Connection connection = null;
        Statement statement = null;

        try {
            Class.forName(JDBC_DRIVER);
            System.out.println("connection to ....");

            connection = DriverManager.getConnection(CONN_URL, USER, PASS);
            connection.setAutoCommit(false);
            connection.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
            System.out.println("create statement。。。");
            statement = connection.createStatement();
            String sql = "update actor set last_update=now() where actor_id=200";
            String insertSQL = "insert into actor (first_name,last_name,last_update) values ('cheng111','xq',now())";
            statement.execute(insertSQL);
            int rows = statement.executeUpdate(sql);
            connection.commit();

        } catch (Exception e) {
            connection.rollback();
        } finally {
            connection.close();
        }

    }


}
